
package org.walklink.agent.plugin.impl.log;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import org.walklink.agent.plugin.IPlugin;
import org.walklink.agent.plugin.InterceptPoint;

/**
 * 日志拦截插件
 *
 * @author lidishan
 */
public class Slf4jLogPlugin implements IPlugin {

    @Override
    public String name() {
        return getClass().getSimpleName();
    }

    @Override
    public InterceptPoint[] buildInterceptPoint() {
        return new InterceptPoint[]{
                new InterceptPoint() {
                    @Override
                    public ElementMatcher<TypeDescription> buildTypesMatcher() {
                        return ElementMatchers.nameStartsWith("org.slf4j");
//                        return ElementMatchers.hasAnnotation(new AnnotationTypeMatcher().matches(PostMapping.class)
                    }

                    @Override
                    public ElementMatcher<MethodDescription> buildMethodsMatcher() {
                        return ElementMatchers.isMethod()
//                                .and(ElementMatchers.any())
                                .and(ElementMatchers.nameStartsWith("info"))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("main")));
                    }
                }
        };
    }

    @Override
    public Class adviceClass() {
        return LogAdvice.class;
    }

}